\name{makeConnector}
\alias{makeConnector}

\title{ Generate connector functions }
\description{
  Generate AOP-style connector functions. The resulting connector
  function can link other functions.
}      
\usage{
makeConnector(expr, connectionOrder = "after")
}
\arguments{
  \item{expr}{ an expression containing the code to place in the heart
    of the resulting connector function.}
  \item{connectionOrder}{ a character string indicating the type of
    connector, either "before" or "after".}
}
\details{

\code{expr} can include \code{origFun}, \code{newFun}, and \code{otherArgs} as
appropriate. \code{otherArgs} are additional named arguments passed to
the connection creating function. As examples, the predefined connector functions are
currently defined as follows:

connectBefore <- makeConnector({ newFun(...); origFun(...) }, connectionOrder = "before")

connectAfter <- makeConnector({ origFun(...); newFun(...); })

connectAround <- makeConnector({ newFun(...); })

modifyResults <- makeConnector({ newFun(origFun(...)); })

Depending on the need, it may be easier to directly use
\code{connectAround} rather than setting up a new connector function.

}
\value{
  A function defined as \code{function(fun, newFun, env =
    parent.frame(), inherits = !exists(funName, env))}.
}
\references{ 
  \url{http://en.wikipedia.org/wiki/Aspect-oriented_programming}
}
\author{ Tom Short }
\seealso{ \code{\link{connectAround.default}} }
}
\examples{
  modifyArgs <- makeConnector({
      do.call("origFun", modifyList(list(...), otherArgs))
  })
  f1 <- function(a = 32, b = 55) a + b
  modifyArgs(f1, a = 12) # otherArgs == list(a = 12)
  f1()

\dontrun{
  # change the defaults to postscript
  library(grDevices)
  modifyArgs(postscript, list(horizontal = FALSE, onefile =
                              FALSE, paper = "special"))
  removeConnects(postscript)
}
}
\keyword{ programming }
\keyword{ methods }
